<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
function objectToArray($d) {
        if (is_object($d)) {
                // Gets the properties of the given object
                // with get_object_vars function
                $d = get_object_vars($d);
        }

        if (is_array($d)) {
                /*
                * Return array converted to object
                * Using __FUNCTION__ (Magic constant)
                * for recursive call
                */
                return array_map(__FUNCTION__, $d);
        }
        else {
                // Return array
                return $d;
        }
}
        
if(isset($id) && $id!=null){
    $id= $id;
    $item=$this->template_model->getTemplate($id);
    $item=objectToArray($item[0]);
    //print_r($item);exit();
}
?>

<div class="clear"></div>
<div style="height: 40px;width: 100%;text-align: center">
    <h1 class="pt8 pb8 mt0 mb0"><?=isset($id)?"Chỉnh Sửa : ":"Thêm mới"?><?=$item["name"]?></h1>
</div>
<div class="grid24">
    <div class="pl12 pr12">
        <table style="width:100%;" class="_form">
                    <tr>
                        <td style="">
                            <div class="_input-label">
                                <div class="input">
                                    <input type="text" id="txt_product_detail_name" placeholder="" value="<?=$item["name"]?>"/>
                                    <input type="hidden" id="txt_product_detail_id" placeholder="" value="<?=$item["id"]?>"/>
                                    <div class="label"><label>Name</label></div>
                                </div>
                            </div>
                        </td>
                        <td class="space"></td>
                        <td>
                            <div class="_input-label">
                                <div class="input">
                                    <input type="text" id="txt_product_detail_title" placeholder="" value="<?=$item["title"]?>"/>
                                    <div class="label"><label>Tiêu đề</label></div>
                                </div>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td style="position: relative">
                            <div class="_input-label">
                                <div class="input">
                                    <input type="text" id="txt_product_detail_image" placeholder="" value="<?=$item["image"]?>"/>
                                    <div class="label"><label>Hình ảnh</label></div>
                                </div>
                            </div>
                            <div class="icon16 hover50 tooltip" style="position: absolute;top:5px;right:0px;cursor: pointer"
                                onclick="BrowseServer( 'Images:/', 'txt_product_detail_image' );"
                                title="Chọn hình ảnh"
                                >
                                <img src="<?=base_url()?>images/icon/16/folder_explore.png"/>
                            </div>
                        </td>
                        <td class="space"></td>
                        <td style="position: relative">
                            <div class="_input-label">
                                <div class="input">
                                    <input type="text" id="txt_product_detail_image1x" placeholder="" value="<?=$item["image1x"]?>"/>
                                    <div class="label"><label>Hình 1X</label></div>
                                </div>
                            </div>
                            <div class="icon16 hover50 tooltip" style="position: absolute;top:5px;right:0px;cursor: pointer"
                                onclick="BrowseServer( 'Images:/', 'txt_product_detail_image1x' );"
                                title="Chọn hình ảnh"
                                >
                                <img src="<?=base_url()?>images/icon/16/folder_explore.png"/>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td style="position: relative">
                            <div class="_input-label">
                                <div class="input">
                                    
                                    <input type="text" id="txt_product_detail_image2x"  placeholder="" value="<?=$item["image2x"]?>"/>
                                    <div class="label"><label>Hình 2X</label></div>
                                </div>
                            </div>
                            <div class="icon16 hover50 tooltip" style="position: absolute;top:5px;right: 0px;cursor: pointer"
                                 onclick="BrowseServer( 'Images:/', 'txt_product_detail_image2x' );"
                                 title="Chọn hình ảnh"
                                 >
                                <img src="<?=base_url()?>images/icon/16/folder_explore.png"/>
                            </div>
                        </td>
                        <td class="space"></td>
                        <td style="position: relative">
                            <div class="_input-label">
                                <div class="input">
                                    <input type="text" id="txt_product_detail_image3x" placeholder="" value="<?=$item["image3x"]?>"/>
                                    <div class="label"><label>Hình 3X</label></div>
                                </div>
                                <div class="icon16 hover50 tooltip" style="position: absolute;top:5px;right:0px;cursor: pointer"
                                    onclick="BrowseServer( 'Images:/', 'txt_product_detail_image3x' );"
                                    title="Chọn hình ảnh"
                                    >
                                    <img src="<?=base_url()?>images/icon/16/folder_explore.png"/>
                                </div>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td style="position: relative">
                            <div class="_input-label">
                                <div class="input">
                                    <input type="text" id="txt_product_detail_homepage" placeholder="" value="<?=$item["url"]?>"/>
                                    <div class="label"><label>Home Page</label></div>
                                </div>
                            </div>
                        </td>
                        <td class="space"></td>
                        <td style="position: relative">
                            <div class="_input-label" type="select">
                            <div class="input" type="select">
                                <div class="select">
                                    <select id="cbx_product_detail_category">
                                        <option value="HTML5 Template">HTML5 Template</option>
                                        
                                    </select>
                                </div>
                                <div class="label"><label>Category</label></div>
                            </div>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3">
                            <div class="input-full">
                                <div class="label"><label>Nội dung ngắn gọn</label></div>
                            </div>
                            <div style="padding:27px 10px 0 0;">
                                <textarea class="_s _w100" id="txt_product_detail_brief" rows="3" cols="103" 
                                            style="width: 100%;height: 100px;padding-left: 8px"

                                            ><?=$item["brief"]?></textarea>
                            </div>
                            
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3">

                            
                            <div class="input-full">
                                <div class="label"><label>Nội dung</label></div>
                            </div>
                            <div style="padding:27px 0px 0 0;" id="editor_content">

                            </div>
                                <textarea class="_s _w100 mceEditor" id="txt_product_detail_des" rows="3" cols="103" 
                                            style="width: 100%;height: 200px"

                                            ><?=$item["description"]?></textarea>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3" style="">
                            <span style="color: blue">Thêm lúc : <?=$item["insert"]?></span>
                            <?
                            $u=$item["update"];$d=$item["delete"];
                            if(isset($item["update"])){
                                echo "<br/><span style='color: orange'>Cập nhật lúc : $u</span>";
                            }
                            if(isset($item["delete"])){
                                echo "<br/><span style='color: red'>Xóa lúc : $d</span>";
                            }
                            ?>

                        </td>
                    </tr>
                </table>
        <span id="warningmsg"></span>
        <div class="mybutton icon tooltip" 
            title="Tải Lại"
            onclick="load_product_detail('<?=$id?>');"
            ><div><img src="<?=base_url()?>images/icon/media_floppy_green.png"/><span>Tải lại</span></div></div>
        <div class="mybutton icon tooltip<?=isset($item["delete"])?" disable":""?>" 
            title="Lưu"
            onclick="<?=isset($item["delete"])?"":(isset($id)?"update();":"save();")?>"
            ><div><img src="<?=base_url()?>images/icon/media_floppy_green.png"/><span>Lưu</span></div></div>
        <div class="mybutton icon tooltip" 
            onclick="huy()"
            title="Hủy"
            ><div><img src="<?=base_url()?>images/icon/addg.png"/><span>Hủy</span></div></div>
        <div class="clear"></div>
    </div>
</div>
    <script>
        $(document).ready(function(){
          $("#txt_product_detail_name").focus();
            tinyMCE.init({
                    mode : "textareas",
                    theme : "advanced",
                    editor_selector : "mceEditor",
                    editor_deselector : "mceNoEditor",
                    theme_advanced_resizing : true,
                    theme_advanced_resize_horizontal : false
            });
        });
        
    </script>
